<?php
namespace app\api\model;
use think\Model;
use think\Db;
use think\Cookie;

class Api extends model{
	public function check_login($id_card,$password){
		$info = Db::name('students')->where("id_card",$id_card)->find();
		// dump($info);die;
		if(!$info){
			return json_encode(['code'=>0,'msg'=>'学生信息填写错误']);
			// $data = array('msg'=>'还未登录','status'=>100);
   //  		exit(json_encode($data));
		}
		if ($info['status'] == 0) {
			// return json_encode(['code'=>0,'msg'=>'该学生已被禁用']);
			return json_encode(array('code'=>0,'msg'=>'该学生已被禁用'));
		}
		if($password !=$info['password']){
			return json_encode(array('code'=>0,'msg'=>'密码错误'));
		}

		Cookie::set('student_id_card',$info['id_card'],18000);
		//保存ID
		Cookie::set('student_id',$info['id'],18000);
		return json_encode(['code'=>1,'msg'=>'登陆成功','id'=>$info['id'],'username'=>$info['username'],'major_id'=>$info['major_id']]);

	}

	


}